package com.saic.data.table;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

public class TableConf {
	
	// table
    public String tablename = "";//tableid
    private String tjson = null;// column name
       
	// DIR
    private String hdfsDir = null;// HDFS DIR
    private String ftpDir = null;// FTP DIR
    public boolean DBdelflag = false;
    
    //tbl
    private String tmpHtbl;
    private String historyHtbl;
    public String dataFamily = "CF1";
    private String oracleTbl;
    
	// other
    private String token;// Token
    private int dstartPoint;
    private int dendPoint;
    private String dformat;
    
	public TableConf(String tablename,String content){
		setTablename(tablename);
		JSONObject json = new JSONObject(content);
		setTjson(content);
		setHdfsDir(tablename);
		setFtpDir(json.getString("ftpDir"));
		setHistoryHtbl(json.getString("historyHtbl"));
		setTmpHtbl(json.getString("tmpHtbl"));
		setToken(json.getString("token"));
		setOracleTbl(json.getString("oracleTbl"));
		setDformat(json.getString("dformat"));
		setDstartPoint(json.getInt("dstartPoint"));
		setDendPoint(json.getInt("dendPoint"));
		//setTestMode();
		this.DBdelflag = json.getBoolean("deleteflag");
	}
    
	public void setTestMode() {
		setOracleTbl(getOracleTbl()+"_L");
		setTmpHtbl("test_csv_tmp");
		setHistoryHtbl("test_csv_done");
	}
	
	public List<String> getColList() {
		String content = getTjson();
		JSONObject obj = new JSONObject(content);
		List<String> list = new ArrayList<String>();
		Iterator<String> iter = obj.keys();
		while (iter.hasNext()) {
			String key = iter.next();
			if (key.startsWith("col"))
				list.add(key);
		}
		return list;
	}
	public Map<String,String> getColMap() {
		String content = getTjson();
		JSONObject obj = new JSONObject(content);
		Map<String,String> map = new HashMap<String, String>();
		Iterator<String> iter = obj.keys();
		while (iter.hasNext()) {
			String key = iter.next();
			if (key.startsWith("col"))
				map.put(key, obj.getString(key));
		}
		return map;
	}
	
	/**
	 * @DESC:获取文件名中日期字符串开始位置
	 * @return
	 */
	public int getDstartPoint() {
		return dstartPoint;
	}

	public void setDstartPoint(int dstartPoint) {
		this.dstartPoint = dstartPoint;
	}
    
	/**
	 * @DESC:获取文件名中日期字符串结束位置
	 * @return
	 */
	public int getDendPoint() {
		return dendPoint;
	}

	public void setDendPoint(int dendPoint) {
		this.dendPoint = dendPoint;
	}
    
	/**
	 * @DESC:获取文件日期字符串格式
	 * @return
	 */
	public String getDformat() {
		return dformat;
	}

	public void setDformat(String dformat) {
		this.dformat = dformat;
	}
    
	/**
	 * @DESC:获取存放表参数的json对象
	 * @return
	 */
	public String getTjson() {
		return tjson;
	}

	public void setTjson(String tjson) {
		this.tjson = tjson;
	}
	/**
	 * @DESC:获取表名，用于HDFS目录，标识文件对应的表
	 * @return
	 */
	public String getTablename() {
		return tablename;
	}

	public void setTablename(String tablename) {
		this.tablename = tablename;
	}
	/**
	 * @DESC:获取存放在HDFS文件的路径
	 * @return
	 */
	public String getHdfsDir() {
		return hdfsDir;
	}

	public void setHdfsDir(String hdfsDir) {
		this.hdfsDir = hdfsDir;
	}
	/**
	 * @DESC:获取存放在HDFS文件的路径
	 * @return
	 */
	public String getFtpDir() {
		return ftpDir;
	}

	public void setFtpDir(String ftpDir) {
		this.ftpDir = ftpDir;
	}
    
	/**
	 * @DESC:获取Hbase中临时表表名
	 * @return
	 */
	public String getTmpHtbl() {
		return tmpHtbl;
	}

	public void setTmpHtbl(String tmpHtbl) {
		this.tmpHtbl = tmpHtbl;
	}
	/**
	 * @DESC:获取Hbase中历史表表名
	 * @return
	 */
	public String getHistoryHtbl() {
		return historyHtbl;
	}

	public void setHistoryHtbl(String historyHtbl) {
		this.historyHtbl = historyHtbl;
	}

	public String getToken() {
		return token;
	}
    
	/**
	 * @DESC:获取FTP文件中的行分隔符
	 * @return
	 */
	public void setToken(String token) {
		this.token = token;
	}

	/**
	 * @DESC:获取oracle表表名
	 * @return
	 */
	public String getOracleTbl() {
		return oracleTbl;
	}

	public void setOracleTbl(String oracleTbl) {
		this.oracleTbl = oracleTbl;
	}
	
}
